import React, { useState, useEffect } from 'react';
import { View } from 'react-native';
import { Toast } from '@ant-design/react-native';
import WorkbenchView from '../../components/WorkbenchView';
import { mineLog, selectUser, getReportCount } from '../../comconfig/sqlfun';

const index = ({ navigation, route }) => {
    const [mineLogInfo, setMineLogInfo] = useState({});
    const [usesrInfo, setUserInfo] = useState({});
    const [reportCount, setReportCount] = useState(0);
    const getUserData = async () => {
        try {
            const info = await selectUser();
            setUserInfo(JSON.parse(info));
        } catch (error) {
            Toast.info('获取数据失败', 1, undefined, false);
        }
    };
    const getMineLog = async () => {
        try {
            const list = await mineLog();
            setMineLogInfo(JSON.parse(list));
        } catch (error) {
            Toast.info('获取数据失败', 1, undefined, false);
        }
    };
    const getCount = async () => {
        try {
            const count = await getReportCount();
            setReportCount(count);
        } catch (error) {
            Toast.info('获取数据失败', 1, undefined, false);
        }
    };
    useEffect(() => {
        getMineLog();
        getUserData();
        getCount();
    }, [route]);
    return (
        <View>
            <WorkbenchView
                navigation={navigation}
                mineLogInfo={mineLogInfo}
                usesrInfo={usesrInfo}
                reportCount={reportCount}
            />
        </View>
    );
};

export default index;
